﻿using CNKI.TPI.Web.Admin.Model;
using CNKI.TPI.Web.Base;
using CNKI.TPI.Web.Search.Model;
using KNet.Data.KBaseClient;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace CNKI.TPI.Web.Admin.IDAO
{
    public interface IMultiDBPublishDAO
    {
        /// <summary>
        /// 保存跨库分类
        /// </summary>
        /// <returns></returns>
        bool SaveDBClass(DBCLASS obj);
        /// <summary>
        /// 修改跨库分类
        /// </summary>
        /// <returns></returns>
        bool UpdateDBClass(string name,string code);
        /// <summary>
        /// 删除跨库分类
        /// </summary>
        /// <returns></returns>
        bool DeleteDBClass(string sql);

        /// <summary>
        /// 保存设置的字段，（排序，检索，概览）
        /// </summary>
        /// <returns></returns>
        bool SaveUsField(DBUSFIELD obj);
        /// <summary>
        /// 更新设置的字段，（排序，检索，概览）
        /// </summary>
        /// <returns></returns>
        bool UpdateUsField(DBUSFIELD obj);
        /// <summary>
        ///  删除设置的跨库字段 FieldType：1=检索字段 2=排序字段 3=概览字段
        /// </summary>
        /// <returns></returns>
        bool DeleteUsField(Expression<Func<DBUSFIELD, bool>> query);

        /// <summary>
        /// 更新DBconfig
        /// </summary>
        /// <param name="configList"></param>
        /// <returns></returns>
        bool UpdateDBClassFromDBConfig(IList<DBCONFIG> configList);

        /// <summary>
        /// 插入DBconfig
        /// </summary>
        /// <param name="configList"></param>
        /// <returns></returns>
        bool AddDBConfig(IList<DBCONFIG> configList);
           /// <summary>
        /// 获取所有已经发布的数据库列表
        /// </summary>
        /// <returns></returns>
        IList<SYS_CMS_DATABASE> GetPublishDBList(PermissionOption option = PermissionOption.FilteringPermissions, bool visible = true);

        /// <summary>
        /// 根据数据库ID获得对应的映射关系
        /// </summary>
        /// <param name="dbID">数据库ID</param>
        /// <returns>映射关系列表</returns>
        IList<SYS_CMS_US_FIELDMAP> GetUSFieldMap(int dbID);

        /// <summary>
        /// 根据主键ID获得对应的映射关系
        /// </summary>
        /// <param name="sysID">主键ID</param>
        /// <returns>映射关系列表</returns>
        SYS_CMS_US_FIELDMAP GetUSFieldMapByID(int sysID);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="fieldIDList"></param>
        /// <returns></returns>
        IList<SYS_CMS_US_FIELD> GetUSFieldByID(IList<int> fieldIDList);

        /// <summary>
        /// 更新SYS_CMS_US_FIELDMAP
        /// </summary>
        /// <param name="configList"></param>
        /// <returns></returns>
        bool UpdateFIELDMAP(SYS_CMS_US_FIELDMAP fieldmap);

        /// <summary>
        /// 插入SYS_CMS_US_FIELDMAP
        /// </summary>
        /// <param name="configList"></param>
        /// <returns></returns>
        bool AddFIELDMAP(SYS_CMS_US_FIELDMAP fieldmap);

        /// <summary>
        /// 删除SYS_CMS_US_FIELDMAP
        /// </summary>
        /// <param name="configList"></param>
        /// <returns></returns>
        bool DeleteFIELDMAP(SYS_CMS_US_FIELDMAP fieldmap);
           /// <summary>
        /// 判断数据库中的字段是否已经设置过映射
        /// </summary>
        /// <param name="dbid"></param>
        /// <param name="dbfieldid"></param>
        /// <returns></returns>
        bool IsExitstDbField(string dbid, string dbfieldid);
         /// <summary>
        /// 判断公共字段是否已经设置过映射
        /// </summary>
        /// <param name="dbid"></param>
        /// <param name="USfieldid"></param>
        /// <returns></returns>
        bool IsExitstUSField(string dbid, string usfieldid);
         /// <summary>
        /// 获取公共映射字段
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        IList<SYS_CMS_US_FIELD> GetUSFiled();
          /// <summary>
        /// 获取数据字段
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        IList<SYS_CMS_DATABASE_FIELD> GetDBFiledByDbCode(string code);
         /// <summary>
        /// 修改时判断公共字段是否已经设置过映射
        /// </summary>
        /// <param name="dbid"></param>
        /// <param name="USfieldid"></param>
        /// <returns></returns>
        bool IsExitstUSField(string dbid, string usfieldid, string sysid);

        /// <summary>
        /// 根据名称获取公共映射字段
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        IList<SYS_CMS_US_FIELD> GetUSFiledByName(string name);

        HS_TABLE_FIELD GetFieldInfo(string dbCode, string fieldName);

        int UpdateFieldInfo(string dbCode, HS_TABLE_FIELD fieldInfo);

        /// <summary>
        /// 保存数据库信息
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        bool SaveDB(SYS_CMS_DATABASE obj);
      
        /// <summary>
        /// 根据数据库信息
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        bool UpdateDB(SYS_CMS_DATABASE obj);
   
        /// <summary>
        /// 保存数据库字段
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        bool SaveDBField(SYS_CMS_DATABASE_FIELD obj);
       
        /// <summary>
        /// 删除对应的数据库字段
        /// </summary>
        /// <param name="dbcode"></param>
        /// <returns></returns>
        bool DelDBField(string strid);
        /// <summary>
        /// 删除数据库
        /// </summary>
        /// <param name="id"></param>
        bool DelDB(string id);

          /// <summary>
        /// 修改数据
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        bool UpdateDBField(SYS_CMS_DATABASE_FIELD obj);
      
          /// <summary>
        /// 删除对应的数据库映射字段SYS_CMS_US_FIELDMAP
        /// </summary>
        /// <param name="dbcode"></param>
        /// <returns></returns>
         bool DelDBFieldMap(string strid);
          /// <summary>
        /// 根据数据库编码删除对应的数据库字段
        /// </summary>
        /// <param name="dbcode"></param>
        /// <returns></returns>
         bool DelFieldByDBCode(string dbcode);
    }
}
